package com.hr.runnerbuddy.overzicht;

import java.util.ArrayList;

import com.hr.accutest.R;
import com.hr.runnerbuddy.database.*;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.GraphView.GraphViewData;
import com.jjoe64.graphview.GraphView.GraphViewSeries;
import com.jjoe64.graphview.LineGraphView;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;

public class Bekijken extends Activity {
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.overview);

		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		int id = extras.getInt("parcourid");
		createDiagram(id);
	}

	public ArrayList<LoopsessiePunt> getLoopsessiepunten(int id) {
		DBAdapter db = new DBAdapter(this);
		db.open();
		ArrayList<LoopsessiePunt> loopsessiepunten = db.getAllLoopsessiePunten(id);
		db.close();

		return loopsessiepunten;
	}

	public GraphViewSeries createLine(ArrayList<LoopsessiePunt> loopsessiepunten) {

		GraphViewData[] data = new GraphViewData[loopsessiepunten.size()];

		for (int i = 0; i < loopsessiepunten.size(); i++) {
			LoopsessiePunt punt = loopsessiepunten.get(i);

			// tijd moet nog berekend worden nu gebruikt hij i
			data[i] = new GraphViewData(i, punt.getSnelheid());
		}

		GraphViewSeries Lijn = new GraphViewSeries(data);
		return Lijn;
	}

	public void createDiagram(int loopsessieid) {
		GraphViewSeries Loopsessie = createLine(getLoopsessiepunten(loopsessieid));

		GraphView schema = new LineGraphView(this, "Overzicht");
		schema.addSeries(Loopsessie);

		LinearLayout layout = (LinearLayout) findViewById(R.id.schema);
		layout.addView(schema);
	}

}
